package tankgame4;

public class Shot implements Runnable{
    int x;
    int y;
    int direct;
    int speed=4;
    boolean isLive = true;


    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
//            System.out.println("敌人子弹："+x+"--"+y);
            switch (direct) {
                case 0://上
                    y-=speed;
                    break;
                case 1://right
                    x+=speed;
                    break;
                case 2://down
                    y+=speed;
                    break;
                case 3://left
                    x-=speed;
                    break;
            }//switch
            if(!(x>=0 && x<1000 &&y>=0 &&y<650 &&isLive)){//子弹范围：填充的黑框里面
                //子弹不再框里 或者子弹击中敌方坦克(但是死亡坦克的位置区域，子弹进不去)
                isLive=false;
                break;
            }

        }//while
    } //run

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }
}
